package upload;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;
import java.io.IOException;

@WebServlet("/upload/up")
@MultipartConfig
public class UpImgs extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       //文件上传
        Part p=req.getPart("file");
        String fileName=p.getSubmittedFileName();
        String path=this.getServletContext().getRealPath("/imgs");
        System.out.println(path);
        path=path+"/"+fileName;
        p.write(path);

        resp.getWriter().write(req.getContextPath()+"/imgs/"+fileName);
    }
}
